package com.adee.java;

// 测试构造函数是不是线程安全的：不安全
public class Test007_Constructor {
    public static Test007_Constructor OBJ;
    private String name;
    public Test007_Constructor(String name) {
        OBJ = this;
        this.name = name;
        sleep(100);

    }
    public static void main(String[] args) {
        new Thread(() -> {
            Test007_Constructor t = new Test007_Constructor("hello");
            System.out.println(t.name); // world
        }).start();
        new Thread(() -> {
            sleep(10);
            OBJ.name = "world";
        }).start();



    }

    public static void sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


